<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="layout" content="main"/>
  <title>Edit Position</title>
</head>
<body>
<div class="nav">
  <span class="menuButton"><a class="home" href="${createLinkTo(dir: '')}">Home</a></span>
  %{--<span class="menuButton"><g:link class="list" action="list">Position List</g:link></span>--}%
  %{--<span class="menuButton"><g:link class="create" action="create">New Position</g:link></span>--}%
</div>
<div class="body">
  <h1>Edit Position</h1>
  <g:if test="${flash.message}">
    <div class="message">${flash.message}</div>
  </g:if>
  <g:hasErrors bean="${positionInstance}">
    <div class="errors">
      <g:renderErrors bean="${positionInstance}" as="list"/>
    </div>
  </g:hasErrors>
  <g:form method="post">
    <input type="hidden" name="eventId" value="${eventId}"/>
    <input type="hidden" name="id" value="${positionInstance?.id}"/>
    <input type="hidden" name="version" value="${positionInstance?.version}"/>
    <div class="dialog">
      <table>
        <tbody>
        <tr class="prop">
          <td valign="top" class="name">
            <label for="name">Name:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'name', 'errors')}">
            <input type="text" id="name" name="name" value="${fieldValue(bean: positionInstance, field: 'name')}"/>
          </td>
        </tr>
        <tr class="prop">
          <td valign="top" class="name">
            <label for="description">Description:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'description', 'errors')}">
            <textarea rows="5" cols="40" id="description" name="description">${fieldValue(bean: positionInstance, field: 'description')}</textarea>
            
          </td>
        </tr>
        <tr class="prop">
          <td valign="top" class="name">
            <label for="location">Location:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'location', 'errors')}">
            <input type="text" id="location" name="location" value="${fieldValue(bean: positionInstance, field: 'location')}"/>
          </td>
        </tr>
        <tr class="prop">
          <td valign="top" class="name">
            <label for="requires">Requires:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'requires', 'errors')}">
            <input type="text" id="requires" name="requires" value="${fieldValue(bean: positionInstance, field: 'requires')}"/>
          </td>
        </tr>
        <tr class="prop">
          <td valign="top" class="name">
            <label for="startDate">Start Date:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'startDate', 'errors')}">
            <g:datePicker name="startDate" value="${positionInstance?.startDate}"></g:datePicker>
          </td>
        </tr>
        <tr class="prop">
          <td valign="top" class="name">
            <label for="endDate">End Date:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'endDate', 'errors')}">
            <g:datePicker name="endDate" value="${positionInstance?.endDate}"></g:datePicker>
          </td>
        </tr>

        %{--<tr class="prop">--}%
        %{--<td valign="top" class="name">--}%
        %{--<label for="volunteers">Volunteers:</label>--}%
        %{--</td>--}%
        %{--<td valign="top" class="value ${hasErrors(bean: positionInstance, field: 'volunteers', 'errors')}">--}%
        %{--<g:select name="volunteers"--}%
        %{--from="${UserAccount.list()}"--}%
        %{--size="5" multiple="yes" optionKey="id"--}%
        %{--value="${positionInstance?.volunteers}"/>--}%

        %{--</td>--}%
        %{--</tr>--}%

        </tbody>
      </table>
    </div>
    <div class="buttons">
      <span class="button"><g:actionSubmit class="save" value="Update Position" action="Update"/></span>
      %{--<span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete"/></span>--}%
    </div>
  </g:form>
  <h1>Volunteers</h1>
  <div class="list">
    <g:if test="${flash.messageVolunteer}">
      <div class="message">${flash.messageVolunteer}</div>
    </g:if>
    <table>
      <thead>
      <tr>
        <g:sortableColumn property="id" title="Id"/>
        <g:sortableColumn property="firstName" title="First Name"/>
        <g:sortableColumn property="lastName" title="Last Name"/>
        <g:sortableColumn property="email" title="Email"/>
        <td></td>
      </tr>
      </thead>
      <tbody>
      <g:if test="${positionInstance?.volunteers.size() == 0}">
        <tr>
          <td colspan=4>No volunteers yet</td>
        </tr>
      </g:if>
      <g:each in="${positionInstance.volunteers}" status="i" var="userAccountInstance">
        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
          <td><g:link action="show" id="${userAccountInstance.id}">${fieldValue(bean: userAccountInstance, field: 'id')}</g:link></td>
          <td>${fieldValue(bean: userAccountInstance, field: 'firstName')}</td>
          <td>${fieldValue(bean: userAccountInstance, field: 'lastName')}</td>
          <td>${fieldValue(bean: userAccountInstance, field: 'email')}</td>
          <td><span class="button"><g:link class="delete" onclick="return confirm('Are you sure?');" controller="position" action="removeVolunteer" params="[positionId:positionInstance.id, userId:userAccountInstance.id]">Remove</g:link></span></td>
        </tr>
      </g:each>
      </tbody>
    </table>
  </div>
  %{--<div class="paginateButtons">--}%
  %{--<g:paginate total="${userAccountInstanceTotal}" />--}%
  %{--</div>--}%
</div>




</div>
</body>
</html>
